-
Notifications
You must be signed in to change notification settings - Fork 1
8-csecaujunseo #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8-csecaujunseo #30
Conversation
|
μ°κ²°λ¦¬μ€νΈλ₯Ό μ¬μ©νμ
¨κ΅°μ... λλ¨ν©λλ€. νμ΄μ¬ 3
import sys
from collections import deque
input = sys.stdin.readline
for _ in range(int(input())):
key_input = input().rstrip()
left = deque()
right = deque()
for ch in key_input:
if ch == '<':
if left:
right.appendleft(left.pop())
elif ch == '>':
if right:
left.append(right.popleft())
elif ch == '-':
if left:
left.pop()
else:
left.append(ch)
print(''.join(left) + ''.join(right)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ½κ² λ΄€λ€κ° ꡬνμμ λ©μΉ«νλ€μ.
μ λ λ¬Έμ λ₯Ό μλ κ·Έλλ‘ κ΅¬νν μ μμκ±°λΌ μκ°νκ³ νμμ΅λλ€.
컀μλ₯Ό μ΄λ»κ² ꡬνν κΉ νλ€κ° listλ₯Ό μ΄μ©ν λΉλ°λ²νΈ λ°°μ΄μ iteratorλ‘ μ κ·Όν΄μ κ²¨μ° νμλ€μ.
C++ μ½λ
#include <iostream>
#include <list>
#include <string>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int TestCaseCount;
cin >> TestCaseCount;
while(TestCaseCount--) {
string password;
cin >> password;
list<char> result;
auto cursor = result.begin();
for(char pw : password) {
if(pw == '<') {
if(cursor != result.begin()) cursor--;
}
else if(pw == '>') {
if(cursor != result.end()) cursor++;
}
else if(pw == '-') {
if(cursor != result.begin()) {
cursor--;
cursor = result.erase(cursor);
}
}
else result.insert(cursor, pw);
}
for(char pw : result)
cout << pw;
cout << '\n';
}
return 0;
}μ½λκ° κ΅μ₯ν κΉλνλ€μ.... μ΄λμ μ΄λ κ² κ΅¬ν λ₯λ ₯μ΄ λμμ§μ 건μ§...
Cλ‘ μ΄ μ λμ ꡬνμ....!
μ λ ꡬνμ μκ°μ λ무 μ€λ μ°λ κ² κ°μ΅λλ€.
μ λ ꡬνμ μ‘°κΈ λ μ°μ΅ν΄μΌ ν κ² κ°μ΅λλ€.
μ΄ λ°©μλ μλ‘λ€μ..! μ’μ μΈμ¬μ΄νΈλ₯Ό μ»μ΄κ°λλ€.. |
νκ΅ μλ£κ΅¬μ‘° μμ
λ λ°°μ λ μ½λλ€μ νμ©ν΄μ κ·Έλ μ§ μ μ€λ ₯μ μμ§ λ°λ₯μ
λλ€ γ
γ
cμΈμ΄λ 2νλ 1νκΈ° λλλ©΄ λ°λ‘ λ²λ¦΄ μμ μ λλ€ γ γ γ |
λνλ μ½λ보λ μ κ° λ무 μ°κ²° 리μ€νΈμ κ½μ¬μμλ κ² κ°λ€μ! 컀μ κΈ°μ€μΌλ‘ μ€νμ μ¬μ©νλκ² κ΅μ₯ν ν₯λ―Έλ‘μ μ΅λλ€. |
9kyo-hwang
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리μ€νΈκ° μ€κ° μμΉμ μμ μ½μ /μμ κ° λΉ λ₯΄κΈ΄ νμ§λ§, κΈ°λ³Έμ μΈ μλ μμ²΄κ° λ°°μ΄ κΈ°λ° μ»¨ν μ΄λλ³΄λ€ λ릴 μ λ°μ μμ£ .
κ·Έλμ μ΄ λ¬Έμ λ Stack 2κ°λ₯Ό μ¬μ©ν΄μ νΈλ κ² λ©λͺ¨λ¦¬λ μλ μ μΌλ‘ ν¨μ¬ ν¨μ¨μ μ΄λλλ€ :)
κΈ°λ³Έμ μΌλ‘λ Stackμ μ μμλ₯Ό Pushνλ€κ°, '<' μ λ ₯μ΄ λ€μ΄μμ λ μλ Stackμ Topμ μμ Stackμ Push, '>' μ λ ₯μ΄ λ€μ΄μ€λ©΄ λ°λλ‘ μμ Stackμ Topμ μλ Stackμ Pushν΄μ£Όλ©΄ μμ°μ€λ½κ² Topμ΄ μ»€μμ μμΉ μν μ μνν©λλ€.
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
cin.tie(nullptr)->sync_with_stdio(false);
int T; cin >> T;
while(T--)
{
string L; cin >> L;
string Str1, Str2;
for(const char Ch : L)
{
if(Ch == '<')
{
if(!Str1.empty())
{
Str2.push_back(Str1.back());
Str1.pop_back();
}
}
else if(Ch == '>')
{
if(!Str2.empty())
{
Str1.push_back(Str2.back());
Str2.pop_back();
}
}
else if(Ch == '-')
{
if(!Str1.empty())
{
Str1.pop_back();
}
}
else
{
Str1.push_back(Ch);
}
}
reverse(Str2.begin(), Str2.end());
cout << Str1 + Str2 << "\n";
}
return 0;
}string μλ£νμ μΌμ§λ§ λ΄λΆμ μΌλ‘ λ°°μ΄μ΄λΌ stackκ³Ό λμΌν μ°μ°μ μ§μν©λλ€. κ·Έλμ Stackμ²λΌ μ¬μ©ν μ μμ΄μ :)
hadongun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ μ λ <, > μ λ ₯μ λ°μΌλ©΄ curosr λ³μ κ°μ +1, -1 νμ¬ μ»€μ μμΉλ₯Ό μ‘°μ νλ λ°©μμΌλ‘ ν΄κ²°ν΄λ³΄μμ΅λλ€.
νμ΄μ¬
import sys
def givemepassword(N):
for i in range(N):
cursor = 0
text = []
line = sys.stdin.readline().strip()
for k in line:
if k == '<':
if cursor > 0:
cursor -= 1
elif k == '>':
if cursor < len(text):
cursor += 1
elif k == '-':
if cursor > 0:
text.pop(cursor-1)
cursor -= 1
else:
text.insert(cursor, k)
cursor += 1
print(''.join(text))
n = int(input())
givemepassword(n)
π λ¬Έμ λ§ν¬
ν€λ‘κ±°
βοΈ μμλ μκ°
2h
β¨ μλ μ½λ
ν€λ‘κ±°λ! μ»΄ν¨ν°κ° λ°μλ€μ΄λ μ λ ₯ μ 보μ κΈ°λ‘, κ·Έ μ€μμλ μ£Όλ‘ ν€λ³΄λλ₯Ό ν΅ν μ λ ₯μ λ°μ΄ν°λ₯Ό μ€κ°μ κ°λ‘μ±λ ν΄νΉμ λ§ν©λλ€. μ¦ λ΄κ° ν€λ³΄λλ‘ μ λ ₯νλ μ 보λ₯Ό κ°λ‘μ±μ λΉλ°λ²νΈ λ±μ μμλ΄λ κ²μ λλ€
λ¬Έμ λ₯Ό 보면 μμλλ‘ μ λ ₯μ λ°μ§λ§ μ€κ°μ μ 보λ₯Ό μμ ν΄μΌ ν μ μμ΄μΌ νλ―λ‘ λ°°μ΄ λμ μ°κ²°λ¦¬μ€νΈλ₯Ό μ¬μ©νμ΅λλ€.
λ¨Όμ ꡬ쑰체 λ Έλλ₯Ό μ μΈν©λλ€. νλμ λ Έλλ μ΄μ λ Έλμ κ°κ³Ό μ΄ν λ Έλμ κ°μ μ§λκ³ μμ΅λλ€.
λ°λΌμ μ€κ°μ μλ‘μ΄ λ Έλκ° μ½μ λ λ μ΄μ λ Έλμ nextκ°κ³Ό μ΄ν λ Έλμ prevκ°λ§ μμ νλ©΄ λ©λλ€.
μλ₯Ό λ€μ΄ aμ c μ¬μ΄μ bλ₯Ό μ½μ νλ€κ³ νμμ λ μλμ a.nextλ cλ₯Ό κ°λ¦¬ν€κ³ μμκ³ c.prevλ aλ₯Ό κ°λ¦¬ν€κ³ μμμ ν μ§λ§ bλ₯Ό μ½μ ν¨μΌλ‘μ¨ a.nextμ c.prevκ° bλ₯Ό κ°λ¦¬ν€κ² λ°λκ² λμμ΅λλ€.
μ½μ κ³Ό μμ μ κΈ°μ€μ 컀μμ λλ€. μ€μ λ§μ°μ€ 컀μμ λκ°μ μν μ ν©λλ€.
컀μκ° κ°λ¦¬ν€λ λ Έλλ₯Ό μμ λλ μ½μ ν©λλ€.
μ΄λ '<' λ '>'κ° μ λ ₯λλ©΄ νμ¬ μμΉλ₯Ό κ°λ¦¬ν€λ 컀μμ μμΉλ₯Ό λ³κ²½ν΄μ£Όλ©΄ λ©λλ€. '-'κ° μ λ ₯λλ©΄ ꡬ쑰체 νλλ₯Ό μμ !
μλμ½λ
π μλ‘κ² μκ²λ λ΄μ©